package com.cbg.archives.service.impl;

import com.cbg.archives.entity.EsArchives;
import com.cbg.archives.repository.IEsArchivesRepository;
import com.cbg.archives.service.IEsArchivesService;
import com.shuyuwl.core.enums.StatusEnum;
import com.shuyuwl.core.exception.SymServiceException;
import com.shuyuwl.core.service.impl.DaoServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 档案分类表 serviceImpl
 *
 * @author wangjuzheng
 * @since 2019-10-16
 */
@Service
@Transactional(rollbackFor = SymServiceException.class)
public class EsArchivesServiceImpl extends DaoServiceImpl<EsArchives, Long, IEsArchivesRepository> implements IEsArchivesService {

    @Resource
    private IEsArchivesRepository esArchivesRepository;

    @Override
    public List<EsArchives> findByPidAndStatus(Long pid, Byte status) {
        return esArchivesRepository.findByPidAndStatusOrderBySortAsc(pid, status);
    }

    @Override
    public List<EsArchives> findAllEsArchivesAndStatus(Byte status) {
        return esArchivesRepository.findByStatusOrderBySortAsc(status);
    }

    @Override
    public EsArchives findByIdAndStatus(Long id, Byte status) {
        return esArchivesRepository.findByIdAndStatusOrderBySortAsc(id, status);
    }

    @Override
    public Integer getMaxSort(Long pid, Byte status) {
        return esArchivesRepository.getMaxSort(pid, status);
    }

    @Override
    public List<EsArchives> findByPidAndCategoryName(Long categoryPid, String categoryName) {
        return esArchivesRepository.findByPidAndNameAndStatus(categoryPid, categoryName, StatusEnum.OK.getCode());
    }
}
